﻿using Dapper;
using OddUserManager.Data.IRepositories;
using OddUserManager.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OddUserManager.Data.Repositories
{
    public class RealTimeTeamRemarkInfoRepository : RealTimeMacthDapperBaseRepository<TeamRemarkInfo, int>, IRealTimeTeamRemarkInfoRepository
    {
        public TeamRemarkInfo Get(int id)
        {
            var sql = $"select * from TeamRemarkInfo  where id={id}";
            using (var con = GetOpenConnection())
            {
                return con.Query<TeamRemarkInfo>(sql, null, null, true, 3000, null).FirstOrDefault();
            }
        }

        public IEnumerable<TeamRemarkInfo> GetAllList()
        {
            throw new NotImplementedException();
        }

        public List<TeamRemarkInfo> GetTeamRemarkByTeamId(int teamId)
        {
            var sql = $"select * from TeamRemarkInfo  where TeamId={teamId}";
            using (var con = GetOpenConnection())
            {
                return con.Query<TeamRemarkInfo>(sql, null, null, true, 3000, null).AsList();
            }
        }

        public TeamRemarkInfo GetTeamRemarkByTeamIdAndUserId(int teamId, int appUserId)
        {
            var sql = $"select * from TeamRemarkInfo  where TeamId={teamId} and AppUserId = {appUserId}";
            using (var con = GetOpenConnection())
            {
                return con.Query<TeamRemarkInfo>(sql, null, null, true, 3000, null).FirstOrDefault();
            }
        }

        public bool InsertOrUpdate(TeamRemarkInfo entity)
        {
            var t = Get(entity.Id);
            if (null == t)
            {
                return Insert(entity);
            }
            else
            {
                return Update(entity);
            };
        }

        public IEnumerable<TeamRemarkInfo> LoadPageList(int startPage, int pageSize, out int rowCount, Func<TeamRemarkInfo, bool> where, Func<TeamRemarkInfo, object> order)
        {
            throw new NotImplementedException();
        }
    }
}
